FROM ubuntu:18.04


ENV DEBIAN FRONTEND=noninteractive


RUN apt-get update && \
    apt-get install -y curl wget && \
    apt-get clean && \
    rm -rf /var/lib/apt/lists/*


ENV INSTALL_DIR=/opt
WORKDIR SINSTALL_DIR

COPY jdk-8u162-linux-x64.tar.gz . 
RUN tar -zxf jdk-8u162-linux-x64.tar.gz -C $INSTALL_DIR && \
    rm jdk-8u162-linux-x64.tar.gz && \
    mv $INSTALL_DIR/jdk1.8.0_162 $INSTALL_DIR/jdk

ENV JAVA_HOME=${INSTALL_DIR}/jdk
ENV PATH=$JAVA_HOME/bin:$PATH
ENV PATH=$JAVA_HOME/jre/bin:$PATH


COPY apache-tomcat-8.5.99.tar.gz .
RUN tar -zxf apache-tomcat-8.5.99.tar.gz -C $INSTALL_DIR && \
    rm apache-tomcat-8.5.99.tar.gz && \
    mv ${INSTALL_DIR}/apache-tomcat-8.5.99 ${INSTALL_DIR}/tomcat


RUN groupadd -r tomcat && useradd -r -g tomcat -d $INSTALL_DIR/tomcat -s /sbin/nologin tomcat && \
    chown -R tomcat:tomcat $INSTALL_DIR/tomcat


EXPOSE 8080

USER tomcat
CMD ["sh", "-c", "$INSTALL_DIR/tomcat/bin/catalina.sh run"]
